<!--promoteB  -->
<template>
  <div class="promoteB content_box">
    <div class="header_row flex align-center flex-wrap" v-if="hasBtn('promoteBonus:query')">
      <div class="flex align-center m-r-2">
        <span>方案：</span>
        <el-input v-model="searchObj.Name" placeholder="搜索方案名称" clearable></el-input>
      </div>
      <div class="flex align-center m-r-2">
        <span>时间：</span>
        <el-date-picker v-model="searchObj.timeValue" clearable value-format="yyyy-MM-dd HH:mm:ss" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </div>
      <!-- 新增的下拉框 -->
      <div class="flex align-center m-r-2">
        <span>方案类型：</span>
        <el-select v-model="value" placeholder="所有方案">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </div>

      <el-button type="primary" @click="handleFilter">查询</el-button>
    </div>

    <div class="m-b-1 neck_box flex align-center space-between">
      <div>
        <el-button v-if="hasBtn('promoteBonus:add')" type="success" @click="(currentItem = {}), (showForm = true)">新增方案</el-button>
        <!-- <el-button type="danger">批量删除</el-button> -->
        <el-button v-if="hasBtn('promoteBonus:export')" type="warning" disabled>导出列表</el-button>
      </div>
      <pagination v-show="total > 0" :total="total" :page.sync="listQuery.PageIndex" :limit.sync="listQuery.PageSize" @pagination="getList" />
    </div>
    <el-table v-loading="listLoading" :data="list" @sort-change="sortChange" sortable="custom" border style="width: 100%" row-key="Id" stripe @expand-change="expand">
      <el-table-column fixed type="expand">
        <template slot-scope="{ row }">

          <div class="table-expand">
            <div class="table-expand-boxs" :class=" idx%2 == 0 ? '' : 'box-bg' " v-for="(cell, idx) of row.Settings" :key="idx">
              <div class="table-expand-box">{{ cell.Sname }}</div>
              <div class="table-expand-box">{{ '达标金额：' + cell.Target + '元' }}</div>
              <div class="table-expand-box">{{ '奖励金额：' + cell.Target + '元' }}</div>
              <div class="table-expand-box">{{ '开始时间: ' + cell.StartTime + '天' }}</div>
              <div class="table-expand-box">{{ '结束时间: ' + cell.EndTime + '天' }}</div>
            </div>
          </div>

          <!-- <div
            v-if="row.Settings"
            class="flex m-t-1 align-center space-between ladder_item"
          >
            <div class="flex-1">
              <div
                class="flex align-center space-between ladder_cell"
                v-for="(cell, idx) of row.Settings"
                :key="idx"
              >
                <div class="flex align-center m-r-1">
                  <span class="tit_span nowarp">{{ cell.Sname }}</span>
                </div>
                <div class="info_group">
                  <div class="flex align-center">
                    <span class="tit_span nowarp">达标金额：</span>
                    <span class="nowarp">{{ cell.Target }}元</span>
                  </div>
                  <div class="flex align-center">
                    <span class="tit_span nowarp">奖励金额：</span>
                    <span class="nowarp">{{ cell.Award }}元</span>
                  </div>
                  <div class="flex align-center">
                    <span class="tit_span nowarp">开始时间：</span>
                    <span class="nowarp">{{ cell.StartTime }}天</span>
                  </div>
                  <div class="flex align-center">
                    <span class="tit_span nowarp">结束时间：</span>
                    <span class="nowarp">{{ cell.EndTime }}天</span>
                  </div>
                </div>
              </div>
            </div>
          </div> -->

        </template>
      </el-table-column>
      <el-table-column fixed type="index" label="序号" width="80" align="center">
      </el-table-column>
      <el-table-column prop="Sname" label="方案名称" align="center" sortable>
      </el-table-column>
      <el-table-column prop="IsSystem" label="方案类型" align="center" sortable>
        <template slot-scope="scope">
          <div>
            {{
              scope.row.IsSystem == 1
                ? "系统方案"
                : scope.row.IsSystem == 2
                ? "身份方案"
                : scope.row.IsSystem == 3
                ? "公司方案"
                : "机构团队方案"
            }}
          </div>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="UserName" label="方案所属" align="center">
      </el-table-column> -->
      <el-table-column prop="Remark" label="备注" align="center" sortable>
      </el-table-column>
      <el-table-column prop="CreateBy" label="创建人员" align="center" sortable>
      </el-table-column>
      <el-table-column prop="CreateDate" label="创建时间" align="center" sortable width="180">
      </el-table-column>
      <el-table-column prop="UpdateBy" label="修改人员" align="center" sortable>
      </el-table-column>
      <el-table-column prop="UpdateDate" label="修改时间" align="center" sortable width="180">
      </el-table-column>
      <el-table-column label="是否有效" align="center" sortable>
        <template slot-scope="scope">
          <!-- :disabled="!hasBtn('promoteBonus:active') ? true : !(scope.row.IsSystem == 1)" switch除系统身份不能编辑 -->
          <el-switch :disabled="!hasBtn('promoteBonus:active')" v-model="scope.row.IsActive" @change="switchChange(scope.row.Id, scope.row.IsActive)">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="150" align="center" v-if="hasBtn('promoteBonus:edit') || hasBtn('promoteBonus:delete')">
        <template slot-scope="scope">
          <!-- :disabled="!(scope.row.IsSystem == 1)" 编辑button除系统身份不能编辑 -->
          <el-button v-if="hasBtn('promoteBonus:edit')" type="primary" size="small" @click="(currentItem = $deepClone(scope.row)), (showForm = true)">编辑</el-button>
          <el-button v-if="hasBtn('promoteBonus:delete')" @click="$delConfirm(() => del(scope.row.Id))" type="danger" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <PromoteBonusForm :show.sync="showForm" :form-data="currentItem" @finish="getList"></PromoteBonusForm>
  </div>
</template>

<script>

  import { getStandardList, getStandardDetail, deleteStandard, validStandard } from '@/api/EquityManage/promoteBonus'
  import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  import { deepClone } from '@/utils'
  import PromoteBonusForm from './promote_components/PromoteBonusForm'


  export default {
    //import引入的组件需要注入到对象中才能使用
    name: 'promoteB',
    components: { Pagination, PromoteBonusForm },
    data() {
      //这里存放数据
      return {
        options: [ //下拉框值
          {
            value: 0,
            label: '所有方案'
          },
          {
            value: 2,
            label: '身份方案'
          },
          {
            value: 1,
            label: '系统方案'
          },
          // {
          //   value: 3,
          //   label: '公司方案'
          // },
          {
            value: 4,
            label: '团队方案'
          }
        ],
        value: 0, //下拉框显示的值
        dialogVisible: false,
        dialogType: "add",
        showForm: false,
        currentItem: {},
        list: [],
        total: 0,
        listLoading: true,
        searchObjTmpl: {},
        searchObj: {
          Name: '',
          timeValue: '',
          userName: "",
        },
        listQuery: {
          PageIndex: 1,
          PageSize: 10,
          IsPaging: true, //是否分页
          SortName: 'CreateDate',
          SortType: false,
          IsSystem: 0
        },
        currentDetail: {}
      };
    },
    //监听属性 类似于data概念
    computed: {
      dialogTitle() {
        return this.dialogType == 'add' ? '新增方案' : '编辑方案'
      },
    },
    //监控data中的数据变化
    watch: {},
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {
      this.searchObjTmpl = deepClone(this.searchObj)
      this.getList()
    },
    //方法集合
    methods: {
      resetFilter() {
        this.searchObj = deepClone(this.searchObjTmpl)
        this.handleFilter()
      },
      sortChange(data) {
        const { prop, order } = data
        this.listQuery.SortName = prop
        if (order === 'ascending') {
          this.listQuery.SortType = true
        } else {
          this.listQuery.SortType = false
        }
        this.handleFilter()
      },
      handleFilter() {
        this.listQuery.PageIndex = 1
        this.getList()
      },
      getQuery() {
        const params = {
          ...this.searchObj,
          ...this.listQuery,
        }
        if (params.timeValue && params.timeValue.length) {
          params.StartTime = params.timeValue[0]
          params.EndTime = params.timeValue[1]
        }
        return params
      },

      async getList() {
        this.listLoading = true
        this.listQuery.IsSystem = this.value
        const params = this.getQuery()
        const { Data, Total } = await getStandardList(params)
        this.listLoading = false
        if (Data) {
          Data.forEach(item => {
            for (let cell in item) {
              if (!item[cell] && (this.$getType(item[cell]) !== 'Number')) {
                item[cell] = '-'
              }
            }
          })
        }
        this.list = Data || []
        this.total = Total || 0
      },
      async del(id) {
        const { code } = await deleteStandard({
          Id: id
        })
        if (code == 200) {
          this.$notify({
            title: '删除成功',
            message: 'success',
            type: 'success',
            duration: 2000
          })
          this.getList()
        }
      },
      async valid(id) {
        const { code } = await validStandard({
          Id: id
        })
        if (code == 200) {
          this.$notify({
            title: '切换成功',
            message: 'success',
            type: 'success',
            duration: 2000
          })
          this.getList()
        }
      },
      expand(row, expand) {
        if (!row.OpenExpand) {
          row.OpenExpand = true
          this.getDetail(row)
        }

      },
      async getDetail(row) {
        const { data } = await getStandardDetail({
          Id: row.Id
        })
        // row.Mains = data.Mains
        this.$set(row, 'Settings', data.Settings)
      },
    }
  }
</script>
//@import url(); 引入公共css类
<style  scoped>
  .info_group {
    width: 65%;
  }
  .promoteB >>> .el-dialog {
    min-width: 560px;
  }

  .ladder_item {
    width: 95%;
    border-bottom: 1px solid #cecece;
    padding: 5px 0;
  }
  .ladder_cell + .ladder_cell {
    border-top: 2px dashed #f6bcbc;
  }
  .ladder_cell {
    padding: 5px 0;
  }
  .ladder_name {
    /* width: 100px !important; */
    margin-right: 3%;
  }

  .el-icon-circle-close {
    font-size: 18px;
    transition: color 0.25s linear;
  }
  .el-icon-circle-close:hover {
    color: #cecece;
    cursor: pointer;
  }
  .table_ladname {
    width: 30%;
    font-size: 16px;
  }
</style>
